package com.compuvest.tld;

// <editor-fold defaultstate="collapsed" desc="import">
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;

import com.compuvest.web.Items;
// </editor-fold>

public class Navigation extends TagSupport {

    private int categoryID;
    private int subcategoryID;
    //private int lowPrice;
    //private int hiPrice;
    private Items items;
    //private String popUrl;

    public void setCategoryID(int categoryID)               { this.categoryID = categoryID; }
    public void setSubcategoryID(int subcategoryID)         { this.subcategoryID = subcategoryID; }
    //public void setLowPrice(int lowPrice)                   { this.lowPrice = lowPrice; }
    //public void setHiPrice(int hiPrice)                     { this.hiPrice = hiPrice; }
    public void setItems(Items items)                       { this.items = items; }
    //public void setPopUrl(String popUrl)                    { this.popUrl = popUrl; }

// <editor-fold defaultstate="collapsed" desc="doStartTag()">
    @Override
    public int doStartTag() throws JspException {

        String pageName = (String)pageContext.getSession().getAttribute("pageName");
        String thisURL = "./";//(String)pageContext.getSession().getAttribute("thisURL");
        String httpLink = "./";//pageContext.getServletContext().getInitParameter("http");
        //if(thisURL == null) {
        //    thisURL = httpLink;
        //}

        StringBuilder line = new StringBuilder(1000);
        line.append("<div id='cv_nav'>");

        line.append(" &#8226; <a href='").append(httpLink).append("'>Home</a> ");
        if(pageName != null) {
            line.append(" &#8226; <a href='").append(thisURL).append("'>");
            line.append(pageName).append("</a> ");
        }

        if(categoryID != 0 && items.getCategoryName() != null) {
            line.append(" &#8226; <a href='").append(thisURL);
            line.append("?pg=0&cid=").append(categoryID).append("'>");
            line.append(items.getCategoryName()).append("</a> &#8226; ");
            if(subcategoryID != 0 && items.getSubcategoryName() != null) {
                line.append("<a href='").append(thisURL).append("?pg=0&cid=").append(categoryID);
                line.append("&sid=").append(subcategoryID).append("'>");
                line.append(items.getSubcategoryName()).append("</a>");
            }
        }
        line.append("<b>").append(items.getEventTime()).append("</b>");
        line.append("</div>\n");

        try {
            pageContext.getOut().print(line.toString());
//            pageContext.getOut().print(line.toString() +"<br>"+line.length()+" t="+(int)(System.currentTimeMillis()-startEvent));
        }
        catch(java.io.IOException e) {
                throw new JspTagException("Navigation: " + e.getMessage());
        }

        return SKIP_BODY;
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="doEndTag()">
    @Override
    public int doEndTag() {
        return EVAL_PAGE;
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="release()">
    @Override
    public void release() {
        items = null;
        //popUrl = null;
    }
// </editor-fold>
}
